package mango.server;

import java.util.Hashtable;

public class Protocol {
	public Hashtable<String, Integer> bin = null;

	public Connection parent = null;

	public Protocol(Connection c) {
		parent = c;
		bin = new Hashtable<String, Integer>();
		loadHashTable(bin);
	}

	public void loadHashTable(Hashtable t) {
		t.put("user_login", 1);
		t.put("user_logout", 2);
		t.put("user_savedata", 3);
		t.put("user_loaddata", 4);
		t.put("player_updatepos", 5);
	}

	public void execute(String command, String[] args) {
		if (bin.containsKey(command)) {
			try {
			switch (bin.get(command)) {
			case 1:
				userLogin(args[0], args[1]);
				break;
			case 2:
				userLogout(args[0], args[1]);
				break;
			case 3:
				userSaveData(args[0], args[1], args[2]);
				break;
			default:
				parent.pushToClient("<!> Command '" + command +"' has been indexed in the hash table,");
				parent.pushToClient("    but does not link to some method.  Please contact the server");
				parent.pushToClient("    administrator to get your method added properly.");
			}
			}
			catch (ArrayIndexOutOfBoundsException e) {
				parent.pushToClient("<!> Wrong number of arguments given for command "+command);
			}
		} else {
			parent.pushToClient("<!> Unknown Command: " + command);
		}
	}

	public void userLogin(String username, String password) {
	}

	public void userLogout(String username, String password) {
	}

	public void userSaveData(String username, String password, String urlToData) {
	}

	public void returnUnknownCommandMsg(String com) {
		
	}
}
